package cn.yueranzs.system.service.impl;

import cn.yueranzs.response.ResultCode;
import cn.yueranzs.system.mapper.RoleMapper;
import cn.yueranzs.system.pojo.Role;
import cn.yueranzs.system.service.RoleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author yueranzs
 * @since 2021-11-09
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {

    @Resource
    private RoleMapper roleMapper;

    @Transactional(propagation = Propagation.SUPPORTS,rollbackFor = Exception.class)
    @Override
    public List<Role> findRoleList(Role role) {
        return list(new QueryWrapper<Role>().lambda().select(Role::getId,Role::getRoleName,Role::getRemark).eq(Role::getStatus, ResultCode.NODELETE.getCode()));
    }

    /**
     * 查询已拥有的角色列表
     *
     * @param userId
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS,rollbackFor = Exception.class)
    @Override
    public List<Role> hasRoleList(Long userId) {
        return roleMapper.hasRoleList(userId);
    }
}
